//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.user.service;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.live.tool.commons.IAES;
import com.ruoyi.live.tool.utils.HttpPostUtils;
import com.ruoyi.live.user.domain.ItmcCenterUser;
import com.ruoyi.live.user.domain.Res;

import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class UserCenterService {
    protected final String CKECK_USER = "/open/user/checkUser";
    protected final String LOGIN_USER = "/open/user/loginUser";
    protected final String UPDATE_USER = "/open/user/updateUser";
    protected final String INSERT_USER = "/open/user/insertUser";
    protected final String UPDATE_IMG = "/open/user/uploadImg";
    protected final String IMG_URL = "/open/user/preview/";
    protected final String UPDATE_USER_LIST = "/open/user/updateUserList";

    public UserCenterService() {
    }

    public abstract String getUrl();

    public abstract String getKey();

    public abstract String getToken();

    public abstract ItmcCenterUser covert(Object var1);

    public String uploadFile(Long id, HttpServletRequest request) throws Exception {
        try {
            Res res = (Res) JSON.parseObject(HttpPostUtils.getInstance().sendFilePost(id, this.getKey(), this.getToken(), this.getUrl() + "/open/user/uploadImg", request), Res.class);
            return "10000".equals(res.getCode()) ? this.getUrl() + "/open/user/preview/" + res.getData() : null;
        } catch (Exception var4) {
            var4.printStackTrace();
            throw var4;
        }
    }

    public String uploadFileByPath(Long id, String path) throws Exception {
        try {
            Res res = (Res)JSON.parseObject(HttpPostUtils.getInstance().sendFilePostByPath(id, this.getKey(), this.getToken(), this.getUrl() + "/open/user/uploadImg", path), Res.class);
            return "10000".equals(res.getCode()) ? this.getUrl() + "/open/user/preview/" + res.getData() : null;
        } catch (Exception var4) {
            var4.printStackTrace();
            throw var4;
        }
    }

    public Boolean checkUser(Object user) throws Exception {
        try {
            Res res = (Res)JSON.parseObject(HttpPostUtils.getInstance().sendPost(JSON.toJSONString(this.covert(user)), this.getKey(), this.getToken(), this.getUrl() + "/open/user/checkUser"), Res.class);
            return "10000".equals(res.getCode()) && "0".equals(res.getData()) ? false : true;
        } catch (Exception var3) {
            var3.printStackTrace();
            throw var3;
        }
    }

    public ItmcCenterUser loginUser(Object user) throws Exception {
        try {
            Res res = (Res)JSON.parseObject(HttpPostUtils.getInstance().sendPost(JSON.toJSONString(this.covert(user)), this.getKey(), this.getToken(), this.getUrl() + "/open/user/loginUser"), Res.class);
            if ("10000".equals(res.getCode())) {
                ItmcCenterUser obj = (ItmcCenterUser)JSON.parseObject(IAES.decryptToStr(res.getData(), this.getKey()), ItmcCenterUser.class);
                return obj.getId() == null ? null : obj;
            } else {
                return null;
            }
        } catch (Exception var4) {
            var4.printStackTrace();
            throw var4;
        }
    }

    public Boolean updateUser(Object user) throws Exception {
        try {
            Res res = (Res)JSON.parseObject(HttpPostUtils.getInstance().sendPost(JSON.toJSONString(this.covert(user)), this.getKey(), this.getToken(), this.getUrl() + "/open/user/updateUser"), Res.class);
            return "10000".equals(res.getCode()) ? true : false;
        } catch (Exception var3) {
            var3.printStackTrace();
            throw var3;
        }
    }

    public Boolean updateUserList(List<Object> list) throws Exception {
        try {
            List<ItmcCenterUser> users = new ArrayList();
            Iterator var3 = list.iterator();

            while(var3.hasNext()) {
                Object obj = var3.next();
                users.add(this.covert(obj));
            }

            Res res = (Res)JSON.parseObject(HttpPostUtils.getInstance().sendPost(JSONArray.of(users).toString(), this.getKey(), this.getToken(), this.getUrl() + "/open/user/updateUserList"), Res.class);
            return "10000".equals(res.getCode()) ? true : false;
        } catch (Exception var5) {
            var5.printStackTrace();
            throw var5;
        }
    }

    public Long insertUser(Object user) throws Exception {
        try {
            Res res = (Res)JSON.parseObject(HttpPostUtils.getInstance().sendPost(JSON.toJSONString(this.covert(user)), this.getKey(), this.getToken(), this.getUrl() + "/open/user/insertUser"), Res.class);
            return "10000".equals(res.getCode()) ? Long.parseLong(res.getData()) : null;
        } catch (Exception var3) {
            var3.printStackTrace();
            throw var3;
        }
    }
}
